<%--
  Created by IntelliJ IDEA.
  User: 华为
  Date: 2025/3/17
  Time: 0:10
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title>Demo</title>
    <!-- 请勿在项目正式环境中引用该 layui.css 地址 -->
    <link href="//unpkg.com/layui@2.9.23/dist/css/layui.css" rel="stylesheet">
</head>
<body>
<form class="layui-form layui-row layui-col-space16">
    <div class="layui-col-md4">
        <div class="layui-input-wrap">
            <div class="layui-input-prefix">
                <i class="layui-icon layui-icon-username"></i>
            </div>
            <input type="text" name="selectValue"  placeholder="请输入患者姓名/手机号/身份证号码" class="layui-input" lay-affix="clear">
        </div>
    </div>

    <div class="layui-btn-container layui-col-xs12">
        <button class="layui-btn" lay-submit lay-filter="demo-table-search">Search</button>
        <button type="reset" class="layui-btn layui-btn-primary">Clear</button>
    </div>
</form>
<table class="layui-hide" id="ID-table-demo-search"></table>
<script type="text/html" id="toolDemo">
    <div class="layui-clear-space">
<%--        {{#  if(){ }}--%>
        <a class="layui-btn layui-btn-xs" lay-event="set">诊断</a>
<%--        {{#  } }}--%>

    </div>
</script>
<!-- 请勿在项目正式环境中引用该 layui.js 地址 -->
<script src="//unpkg.com/layui@2.9.23/dist/layui.js"></script>
<script>
    layui.use(function(){
        var table = layui.table;
        var form = layui.form;
        var laydate = layui.laydate;
        // 创建表格实例
        table.render({
            elem: '#ID-table-demo-search',
            url: '/visit/getList', // 此处为静态模拟数据，实际使用时需换成真实接口
            cols: [[
                {type: 'radio', title: '😊', fixed: true}, // 单选框
                {field:'visitId', title: '就诊id', width:80, sort: true, fixed: true},
                {field:'registrationId', title: '挂号表id', width:80},
                {field:'visitType', title: '就诊类型', width:80, sort: true,templet:function (obj) {
            if(obj.visitType==0){
                return "初诊"
            }else {
                return "复诊"
            }
        }},
                {field:'sexId', title: '性别', width:80,templet:function (obj) {
                        if(obj.sexId==0){
                            return "女"
                        }else if(obj.sexId==1){
                            return "男"
                        }else{
                            return "保密"
                        }
                    }},
                {field:'patientName', title: '患者姓名', width:80},
                {field:'phoneNumber', title: '手机号码', width:80},
                {field:'birthDate', title: '出生日期', width:80},
                {field:'idCard', title: '身份证号', width:80},
                {field:'age', title: '年龄', width:80},
                {field:'departmentName', title: '科室id', width:80},
                {field:'userName', title: '医生id', width:80},
                {field:'creatTime', title: '就诊日期', width:80},
                {fixed: 'right', title:'操作', width: 134, minWidth: 125, templet: '#toolDemo'}
            ]],
            page: true,
            height: 310,
            toolbar: '#demo-toolbar-setRowChecked',
            request: {
                pageName: 'pageNum', // 页码的参数名称，默认：page
                limitName: 'pageSize' // 每页数据条数的参数名，默认：limit
            },
            parseData: function(res){ // res 即为原始返回的数据
                return {
                    "code": 0, // 解析接口状态
                    "msg": res.message, // 解析提示文本
                    "count": res.data.total, // 解析数据长度
                    "data": res.data.list // 解析数据列表
                };
            },
        });
        // 触发单元格工具事件
        table.on('tool(ID-table-demo-search)', function(obj){ // 双击 toolDouble
            var data = obj.data; // 获得当前行数据
            // console.log(obj)
            if(obj.event === 'set'){
                location.href="/visit/set?visitId="+data.visitId;

            }
        });
        // 日
        // 头工具栏事件
        table.on('toolbar(ID-table-demo-search)', function(obj){
            var checkStatus = table.checkStatus(obj.config.id); //获取选中行状态
            switch(obj.event){
                case 'add':
                    // var data = checkStatus.data;  // 获取选中行数据
                    // layer.alert(JSON.stringify(data));  // 显示 - 仅用于演示
                    // break;
                    location.href="/into/toAdd"
            };
        });
        // 日期
        laydate.render({
            elem: '.demo-table-search-date'
        });
        // 搜索提交
        form.on('submit(demo-table-search)', function(data){
            var field = data.field; // 获得表单字段
            // 执行搜索重载
            table.reload('ID-table-demo-search', {
                page: {
                    curr: 1 // 重新从第 1 页开始
                },
                where: field // 搜索的字段
            });
            layer.msg('搜索成功<br>此处为静态模拟数据，实际使用时换成真实接口即可');
            return false; // 阻止默认 form 跳转
        });
    });
</script>

</body>
</html>
